package com.gm.wholesale.module.order.view.orderManger;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.ListView;

import androidx.annotation.Nullable;

import com.gm.commonlib.base.baseAdapter.CommonAdapter;
import com.gm.commonlib.base.baseAdapter.ViewHolder;
import com.gm.commonlib.views.popupwindow.Popupwindow2;
import com.gm.wholesale.R;
import com.gm.wholesale.view.bean.PopUseBean;

import java.util.List;

public class ChoicePrintPopView extends LinearLayout {
    private Context mContext;
    private ListView listView;
    private OnChoiceListener mListener;

    public void setOnChoiceUnitListener(OnChoiceListener listener){
        this.mListener=listener;
    }
    public interface OnChoiceListener{
        void onChoice(PopUseBean popUseBean);
    }

    public ChoicePrintPopView(Context context) {
        super(context);
        initView(context);
    }

    public ChoicePrintPopView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    private void initView(Context context) {
        mContext = context;
        LayoutInflater.from(context).inflate(R.layout.view_pop_choice, this);
        listView = findViewById(R.id.listView);

    }

    public void showView(List<PopUseBean> popUseBeans){
        listView.setAdapter(new CommonAdapter<>(mContext, popUseBeans, R.layout.list_chhoice_print) {

            @Override
            public void convert(ViewHolder var1, PopUseBean var2) {
                var1.setText(R.id.unitTv, var2.getName());
                var1.getConvertView().setOnClickListener(view -> {
                    Popupwindow2.hiddenPop();
                    mListener.onChoice(var2);
                });
            }
        });
    }
}
